package hibari.server.mail;

import hibari.client.Configuration;
import hibari.client.model.DownloadToken;

import java.io.UnsupportedEncodingException;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class DownloadMessageBuilder {
	private MailTemplate template;

	public DownloadMessageBuilder() {
		this.template = new MailTemplate();
	}

	public MimeMessage createMessage(DownloadToken token, Session session) throws UnsupportedEncodingException,
	MessagingException {
		MimeMessage msg = new MimeMessage(session);
		msg.setFrom(new InternetAddress(Configuration.GMAIL_ID, "HIBARI Project"));
		msg.addRecipient(Message.RecipientType.TO, new InternetAddress(token.getEmail()));
		msg.setSubject("HIBARI sent a gift for your donation!");
		msg.setContent(this.template.generate(token), "text/html");
		return msg;

	}
}
